//
//  SettingsViewController.m
//  RtspClient
//
//  Created by qi tan on 2024/1/5.
//  Copyright © 2024 Andres Rojas. All rights reserved.
//

#import "SettingsViewController.h"
#import "Constants.h"
#import "BeanGunTime.h"
#import "InstructTools.h"
#import "BeanSettings.h"
#import "BeanCurRange.h"

#pragma mark - 宏定义常量
#define  kREQ_TYPE_GET 0
#define  kREQ_TYPE_SET 1

#define kTYPE_0 0
#define kTYPE_1 1
#define kTYPE_2 2
#define kTYPE_3 3
#define kTYPE_4 4
#define kTYPE_5 5
#define kTYPE_6 6
#define kTYPE_7 7



@interface SettingsViewController ()
// 切换目标，显示的label
@property (weak, nonatomic) IBOutlet UILabel *lblTarget;
// 设备语言
@property (weak, nonatomic) IBOutlet UILabel *lblDeviceLanguage;
// 设备时间
@property (weak, nonatomic) IBOutlet UILabel *lblDeviceTime;

// 单位设置
@property (weak, nonatomic) IBOutlet UILabel *lblDeviceUnits;
// 休眠时间
@property (weak, nonatomic) IBOutlet UILabel *lblDeviceSleepTime;
// app版本信息
@property (weak, nonatomic) IBOutlet UILabel *lblAppVersion;
// 休眠时间，弹框中Label，显示的时间值
@property(strong ,nonatomic) UILabel *lblDialogTime;
// 缓存的设置，枪支时间信息。
@property(nonatomic, strong)BeanGunTime *mGunTime;
@property(nonatomic, strong)BeanSettings *mSettings;
@property(nonatomic, assign)int  mRangeIdx; // 射界range

@end

@implementation SettingsViewController
#pragma mark - 初始化，更新页面UI
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:NSLocalizedString(@"system_setting", nil)]; 
    
    // 1. 获取系统时间
    NSString *strUrl = [NSString stringWithFormat:@"%@%@", kInitURL, kURl_getsystime];
    [self sendHttpRequestWithUrl:strUrl andReqType:kREQ_TYPE_GET andType:kTYPE_0];
    // 2. 获取设置信息
    NSString *strUrl4 = [NSString stringWithFormat:@"%@%@", kInitURL, kURL_getqmsettings];
    [self sendHttpRequestWithUrl:strUrl4 andReqType:kREQ_TYPE_GET andType:kTYPE_4];
    
    // 3. 获取Range
    NSString *strUrl3 = [NSString stringWithFormat:@"%@%@", kInitURL, kURL_getqmrange];
    [self sendHttpRequestWithUrl:strUrl3 andReqType:kREQ_TYPE_GET andType:kTYPE_3];
    
    // 4.本地版本信息
    NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
    NSString *appVersion = [infoDict objectForKey:@"CFBundleShortVersionString"];
    self.lblAppVersion.text = [NSString stringWithFormat:@"Version: %@", appVersion];
}

#pragma mark - 给设备发送http请求
// 发送请求给设备。
- (void)sendHttpRequestWithUrl:(NSString *)urlStr andReqType:(int)reqType andType:(int)type {
    NSLog(@"sendHttpRequestWithUrl: %@", urlStr);
    NSURL *url = [NSURL URLWithString:urlStr];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    // 发送异步请求，获取反馈的结果。
    [NSURLConnection sendAsynchronousRequest:request
                                       queue:[NSOperationQueue mainQueue]
                           completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        // response，data，error
        if(!connectionError) {// 请求是否有错误
            int code = connectionError.code;
            NSLog(@"result:%d", code);
            // 二进制数据转成NSString
            NSString  *html = [[NSString alloc] initWithData:data encoding: NSUTF8StringEncoding];
            // 返回的数据。
            [self httpResponseWithReqType:reqType andType:type andCode:code andResult:html];
            
        } else {
            NSLog(@"连接错误 %@",connectionError);
        }
    }];
}

// 处理设备返回的结果。
- (void)httpResponseWithReqType:(int)reqType andType:(int)type andCode:(int)code andResult:(NSString *)result {
    NSLog(@"reqType:%d, type:%d, code:%d, result:%@====", reqType, type, code, result);
    if(reqType == kREQ_TYPE_GET) {
        // 读取数据
        NSString *payLoad = result;
        if([payLoad containsString:@"Success"]) {
            NSRange range = [payLoad rangeOfString:@"Success"];
            range.length = range.location;
            range.location = 0;
            payLoad = [payLoad substringWithRange:range];
        } else if([payLoad containsString:@"SvrFuncResult"]) {
            // 截取前面的内容
            NSRange range = [payLoad rangeOfString:@"SvrFuncResult"];
            payLoad = [payLoad substringToIndex:range.location];
        }
        NSMutableDictionary *dict = [self dictionaryWithDeviceString:payLoad];
        if(type == kTYPE_3) {
            BeanCurRange *curRange = [BeanCurRange beanWithDict:dict];
            self.mRangeIdx = curRange.curRange;
            [self updateRangeByUIIndex: curRange.curRange];
            
        } else if (type == kTYPE_4) {
            BeanSettings *settings = [BeanSettings beanWithDict:dict];
            self.mSettings = settings;
            [self updateSettingsUI];
//            mSettings
        } else if (type == kTYPE_0) {
            BeanGunTime *gunTime = [BeanGunTime beanWithDict:dict];
            NSLog(@"!!!!%@", [gunTime getShowTime]);
            if(gunTime != nil && [gunTime getShowTime] != nil){
                self.lblDeviceTime.text = [gunTime getShowTime];
                self.mGunTime = gunTime;
                NSLog(@"set label time %@", [gunTime getShowTime]);
            }
        }

   } else {
       // 设置数据
       result = [result stringByReplacingOccurrencesOfString:@"\r\n" withString:@""];
       if([result isEqualToString:@"Success"]) {
           [self showAlert:NSLocalizedString(@"operate_success", nil)];
       } else {
           [self showAlert:NSLocalizedString(@"operate_fail", nil)];
       }
       NSLog(@"-%@-",result);
   }
}

// 更新本地显示
- (void)updateRangeByUIIndex:(int) range {
    NSMutableArray *arrayRange = [NSMutableArray array];
    for (int i=0; i<7;i++ ) {
        NSString *imgName = [NSString stringWithFormat:@"qm_range_%01d", i];
        NSString *title = NSLocalizedString(imgName, nil);
        // 添加到集合中
        [arrayRange addObject:title];
    }
    NSString *rangeName = arrayRange[range];
    self.lblTarget.text = rangeName;
}

// 更新设置信息
- (void)updateSettingsUI {
    if(self.mSettings == nil) return;
    
    // 语言，单位，休眠时长
    NSString *unitsStr = (self.mSettings.units == 1) ? @"MOA": @"MIL";
    self.lblDeviceUnits.text = unitsStr;
    NSString *languageStr = nil;
    if(self.mSettings.language == 0) { // 中文
        languageStr = NSLocalizedString(@"qm_language_0", nil);
    } else {
        languageStr = NSLocalizedString(@"qm_language_1", nil);
    }
    self.lblDeviceLanguage.text = languageStr;
    // 休眠时长，初始化更新UI
    self.lblDeviceSleepTime.text = [NSString stringWithFormat:@"%d", 5 * self.mSettings.sleepTimeSec];
}


- (void)showAlert:(NSString *)message {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];
    [self presentViewController:alertController animated:YES completion:nil];
    [self performSelector:@selector(dismiss:) withObject:alertController afterDelay:2.0];
}
- (void)dismiss:(UIAlertController *)alert {
    [alert dismissViewControllerAnimated:YES completion:nil];
}



// 转变成字典数据
// eg: var time="20240106174920"; var timeformat="0"; var timezone="";
- (NSMutableDictionary *)dictionaryWithDeviceString:(NSString *)jsonString {
    if(jsonString == nil) return nil;
    
   //  jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\r\n" withString:@""];
    // 按照分号，切割字符串。
    NSArray * array = [jsonString  componentsSeparatedByString:@";"];
    // NSLog(@"length:%d", array.count);
    NSMutableDictionary * dict1 = [NSMutableDictionary new];
    for (int i=0; i<array.count; i++) {
        NSString *item = [array objectAtIndex:i]; // 每个属性字段
        
        if(![item isEqualToString:@"\r\n"]) {
//            NSLog(@"---------\n item: %@", item);
            NSRange range = [item rangeOfString:@"var "];
            NSRange rangeEqual = [item rangeOfString:@"="];
//            NSLog(@"range:%d, %d", range.location, range.length);
//            NSLog(@"range2：%d, %d", rangeEqual.location, rangeEqual.length);

            // 获取key(根据‘var ’的位置，'='的位置计算出来)，要考虑里面有'\r\n'的情况
            NSRange rangeK = NSMakeRange(range.location + range.length,
                                         rangeEqual.location - range.length - range.location);
            NSString * key = [item substringWithRange:rangeK];
            NSString * value = [item substringFromIndex:rangeEqual.location +1];
            // 去掉双引号
            value = [value stringByReplacingOccurrencesOfString:@"\"" withString:@""];
            // NSLog(@"result item: key=%@, value=%@", key, value);
            [dict1 setObject:value forKey:key];
        }
    }
    return dict1;
}







#pragma mark - 监听列表cell的点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // section分组序号，row组内的序号，序号从0开始。
    if(indexPath.section == 0 && indexPath.row == 0) {
        [self show00_00Dialog];
    } else if (indexPath.section ==1 && indexPath.row ==0){
        // NSLog(@"设备的语言");
        [self show01_00Dialog];
    } else if(indexPath.section ==1 && indexPath.row == 1) {
        // 设备时间
        [self setDeviceTimeDialog];
    } else if(indexPath.section ==1 && indexPath.row == 2) {
        // 设定单位: MIL, MOA
        [self show01_02UnitsDialog];
    } else if(indexPath.section ==1 && indexPath.row == 3) {
        // 休眠时间
        [self show01_03SleepTimeDialog];
    } else if(indexPath.section ==1 && indexPath.row == 4) {
        // 格式化sd
        [self showFormatSDCard];
    } else if(indexPath.section ==1 && indexPath.row == 5) {
        // 设备关机
        [self powerOffDevice];
    }
    // 去掉选中效果
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}





# pragma mark 设置设备 休眠时间
- (void) show01_03SleepTimeDialog {
    // 处理弹框中休眠时间的默认显示
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(0, 20,  self.view.bounds.size.width - 20, 30)];
    slider.maximumValue= 120; // 休眠时间范围0-600s,步进5.
    slider.minimumValue = 0;
    slider.value = self.mSettings.sleepTimeSec; // 设置当前值。
    slider.continuous = true;
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"\n\n\n" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alert.view addSubview:slider];
    
    self.lblDialogTime = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, self.view.bounds.size.width - 20, 20)];
    self.lblDialogTime.textAlignment = NSTextAlignmentCenter;
    [alert.view addSubview: self.lblDialogTime];
    // 设置初始值。弹框中label显示的值。
    self.lblDialogTime.text = [NSString stringWithFormat:@"%d", 5 * self.mSettings.sleepTimeSec];
    
    // 滑动时间监听。
    [slider addTarget:self action:@selector(slideAction:) forControlEvents:UIControlEventValueChanged];
    
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"confirm", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        int value = slider.value;
        self.lblDeviceSleepTime.text = [NSString stringWithFormat:@"%d", 5 * value];
        // 发送数据给设备。
        if(value == self.mSettings.sleepTimeSec) return;
        
        self.mSettings.sleepTimeSec = value;
        [self doSetSetiingParams];
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"cancel cllick");
    }];
    
    [alert addAction:okAction];
    [alert addAction:cancelAction];
    [self presentViewController:alert animated:YES completion:^{}];
}
 


// 弹框的label，显示具体的值。
- (void)slideAction:(UISlider *)slider {
    int value = slider.value;
    self.lblDialogTime.text = [NSString stringWithFormat:@"%d", value * 5];
}



# pragma mark 设置设备单位
- (void) show01_02UnitsDialog {
    UIAlertController *actionSheetController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    for (int i=0; i<2;i++ ) {
        NSString *title = i==0 ? @"MIL" : @"MOA";
        // 选择了item
        UIAlertAction *action = [UIAlertAction actionWithTitle:title
                                                         style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction * _Nonnull action) {
            self.lblDeviceUnits.text = action.title;
            [self setDeviceUnits:i];
        }];
        [actionSheetController addAction:action];
    }
    NSString *cancel = NSLocalizedString(@"Cancel", nil);
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancel
                                                           style:UIAlertActionStyleCancel
                                                         handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"取消");
    }];
    [actionSheetController addAction:cancelAction];
    [self presentViewController:actionSheetController animated:YES completion:nil];
}
- (void) setDeviceUnits: (int)index {
    NSLog(@"select设备units: %d" , index);
    if(self.mSettings.units == index) return;
    
    self.mSettings.units = index;
    [self doSetSetiingParams];
}



# pragma mark 设置设备时间日期
- (void)setDeviceTimeDialog {
    UIDatePicker *datePicker = [[UIDatePicker alloc] init];
    CGRect rect = datePicker.frame;
    rect.origin.x = rect.origin.x + 60;
    rect.origin.y = rect.origin.y + 30;
    datePicker.frame = rect;
    
    datePicker.datePickerMode = UIDatePickerModeDateAndTime;
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"\n\n\n\n" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alert.view addSubview:datePicker];
    
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"confirm", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm"];
        NSString *dateStr = [dateFormatter stringFromDate:datePicker.date];
        NSLog(@"date tiem: %@", dateStr);
        self.lblDeviceTime.text = dateStr;
        
        // 拼装传给设备的时间。
        [dateFormatter setDateFormat:@"yyyy"]; // 年月日
        NSInteger year = [[dateFormatter stringFromDate:datePicker.date] intValue];
        [dateFormatter setDateFormat:@"MM"];
        NSInteger month = [[dateFormatter stringFromDate:datePicker.date] intValue];
        [dateFormatter setDateFormat:@"dd"];
        NSInteger day = [[dateFormatter stringFromDate:datePicker.date] intValue];
        [dateFormatter setDateFormat:@"HH"]; // 时分秒
        NSInteger hour = [[dateFormatter stringFromDate:datePicker.date] intValue];
        [dateFormatter setDateFormat:@"mm"];
        NSInteger minute = [[dateFormatter stringFromDate:datePicker.date] intValue];
        NSInteger seconds = 0; // 秒。
        
        NSString *format = @"%04d%02d%02d%02d%02d%02d"; // 格式与设备返回的格式一致。
        NSString *timeSetStr = [NSString stringWithFormat:format,
                                year,month,day,
                                hour,minute,seconds];
        NSLog(@"trans time: %@", timeSetStr);
        self.mGunTime.time = timeSetStr;
        [self setGunSystemTime:timeSetStr];
        // 发送数据给设备
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"cancel cllick");
    }];
    
    [alert addAction:okAction];
    [alert addAction:cancelAction];
    [self presentViewController:alert animated:YES completion:^{}];
}
# pragma mark 设置事件数据给设备。
- (void)setGunSystemTime:(NSString *)time {
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setObject:time forKey:kKEY_time]; // 时间设置
    NSString *strURL = [InstructTools buildRtspSetInstruct:kInitURL
                                                 andSubUrl:kURl_setsystime
                                              andParamDict:dict];
    [self sendHttpRequestWithUrl:strURL andReqType:kREQ_TYPE_SET andType:0];
    
}




# pragma mark 弹框选择 切换设备语言
- (void) show01_00Dialog {
    UIAlertController *actionSheetController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    for (int i=0; i<2;i++ ) {
        NSString *imgName = [NSString stringWithFormat:@"qm_language_%01d", i];
        NSString *title = NSLocalizedString(imgName, nil);
        // 选择了item
        UIAlertAction *action = [UIAlertAction actionWithTitle:title
                                                         style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction * _Nonnull action) {
            self.lblDeviceLanguage.text = action.title;
            [self selectDeviceLanguage:i];
        }];
        // 添加actionSheet
        [actionSheetController addAction:action];
    }
    NSString *cancel = NSLocalizedString(@"cancel", nil);
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancel
                                                           style:UIAlertActionStyleCancel
                                                         handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"取消");
    }];
    [actionSheetController addAction:cancelAction];
    [self presentViewController:actionSheetController animated:YES completion:nil];
}
- (void) selectDeviceLanguage: (int)index {
    NSLog(@"select设备语言:%d" , index);
    if(self.mSettings.language == index) return; // 未修改语言
    
    self.mSettings.language = index;
    [self doSetSetiingParams];
}

// 设置参数修改
- (void)doSetSetiingParams {
    NSMutableDictionary *dict = [NSMutableDictionary new];
    
    [dict setObject:[NSNumber numberWithInteger:self.mSettings.language] forKey:kKEY_language];
    // 单位，休眠时间(5s步进)，语言。
    [dict setObject:[NSNumber numberWithInteger:self.mSettings.units] forKey:kKEY_units];
    [dict setObject:[NSNumber numberWithInteger:self.mSettings.sleepTimeSec] forKey:kKEY_sleepTimeSec];
    NSString *strURL = [InstructTools buildRtspSetInstruct:kInitURL
                                                 andSubUrl:kURL_setqmsettings
                                              andParamDict:dict];
    [self sendHttpRequestWithUrl:strURL andReqType:kREQ_TYPE_SET andType:kTYPE_4];
}




# pragma mark 弹框选择 切换目标
- (void) show00_00Dialog {
    UIAlertController *actionSheetController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

    // 国际化-代码。
    // NSString *title = NSLocalizedString(@"qm_range_0", nil);
    // app内部国际化。
    for (int i=0; i<7;i++ ) {
        NSString *imgName = [NSString stringWithFormat:@"qm_range_%01d", i];
        NSString *title = NSLocalizedString(imgName, nil);
        // 选择了item
        UIAlertAction *action = [UIAlertAction actionWithTitle:title
                                                         style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction * _Nonnull action) {
            self.lblTarget.text = action.title; // 本地更新UI
            [self selectTarget:i];
        }];
        // 添加actionSheet
        [actionSheetController addAction:action];
    }
    NSString *cancel = NSLocalizedString(@"cancel", nil);
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancel
                                                           style:UIAlertActionStyleCancel
                                                         handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"取消");
    }];
    [actionSheetController addAction:cancelAction];
    [self presentViewController:actionSheetController animated:YES completion:nil];
}

// 处理用户选择，发送http数据给设备。
- (void) selectTarget: (int)index {
    NSLog(@"select:%d" , index);
    // 发送网络请求，更新设备
    self.mRangeIdx = index;
    [self doSetGunRange:index];
}

// 设置参数修改
- (void)doSetGunRange:(int)range {
    NSMutableDictionary *dict = [NSMutableDictionary new];
    
    [dict setObject:[NSNumber numberWithInteger:range] forKey:kKEY_curRange];
    NSString *strURL = [InstructTools buildRtspSetInstruct:kInitURL
                                                 andSubUrl:kURL_setqmrange
                                              andParamDict:dict];
    [self sendHttpRequestWithUrl:strURL andReqType:kREQ_TYPE_SET andType:kTYPE_3];
}


# pragma mark 格式化sd卡


# pragma mark 格式化设备 关机 format_sdcard_hint
- (void)showFormatSDCard {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"prompt", nil)
        message:NSLocalizedString(@"format_sdcard_hint", nil)
        preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"取消");
    }];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"confirm", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    
        [self doSdCardFormat];
    }];
    [alertController addAction:cancelAction];
    [alertController addAction:okAction];
    [self presentViewController:alertController animated:YES completion:nil];
}
// 格式化设备sd卡
- (void)doSdCardFormat {
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setObject:@"format" forKey:kKEY_command];
    NSString *strURL = [InstructTools buildRtspSetInstruct:kInitURL
                                                 andSubUrl:kURL_sdcommand
                                              andParamDict:dict];
    [self sendHttpRequestWithUrl:strURL andReqType:kREQ_TYPE_SET andType:kTYPE_6];
}


# pragma mark 关机 device_shutdown_hint
- (void)powerOffDevice {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"prompt", nil)
        message:NSLocalizedString(@"device_shutdown_hint", nil)
        preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"取消");
    }];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"confirm", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    
        [self doPowerOffDevice];
    }];
    [alertController addAction:cancelAction];
    [alertController addAction:okAction];
    [self presentViewController:alertController animated:YES completion:nil];
}
// 设备关机，发送指令。
- (void)doPowerOffDevice {
    NSMutableDictionary *dict = [NSMutableDictionary new];
    NSString *strURL = [InstructTools buildRtspSetInstruct:kInitURL
                                                 andSubUrl:kURL_poweroff
                                              andParamDict:dict];
    [self sendHttpRequestWithUrl:strURL andReqType:kREQ_TYPE_SET andType:kTYPE_7];
}

@end
